<!DOCTYPE html>
<!-- ng-app -->
<html lang="en" ng-app="app">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="../../../js/plugins/angular/angular.min.js" type="text/javascript"></script>
</head>
<body>
    <div ng-controller="cont">
        <div ng-controller="ss">
            <button ng-click="to_parent()">向父级传播</button>
            <button ng-click="to_child()">向子级传播</button>
            <div ng-controller="cc"></div>
        </div>
        <div ng-controller="bb"></div>
    </div>

    <script>
        var app = angular.module('app',[]);
        app.controller('ss',['$scope',function ($scope) {
            $scope.to_parent = function () {
                $scope.to_parent = function () {
                    $scope.$emit('event_1','事件来源于子级');
                }
                $scope.to_child = function () {
                    $scope.$broadcast('event_2','事件来源于父级');
                }
            }
        }]);
        app.controller('cont',function ($scope) {
            $scope.$on('event_1',function (event,data) {
                console.log('在父级中监听到',data);
            })
            $scope.$on('event_2',function (event,data) {
                console.log('在父级中监听到',data);
            })
        });

        app.controller('cc',function ($scope) {
            $scope.$on('event_1',function (event,data) {
                console.log('在子级中监听到',data);
            })
            $scope.$on('event_2',function (event,data) {
                console.log('在子级中监听到',data);
            })
        });

        app.controller('bb',function ($scope) {
            $scope.$on('event_1',function (event,data) {
                console.log('在同级中监听到',data);
            })
            $scope.$on('event_2',function (event,data) {
                console.log('在同级中监听到',data);
            })
        });
    </script>
</body>
</html>